package com.cn.controller;

import com.cn.service.UserService;
import com.cn.utils.ResultCode;
import com.cn.vo.ReJson;
import com.cn.vo.UserAndTokenVo;
import com.cn.vo.UserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by chenyuncong on 2019/9/12.
 */
@RestController
@RequestMapping("index")
@Api(description = "登陆模块")
public class IndexController {

    @Autowired
    private UserService userService;

    @GetMapping("getUserList")
    public List<UserVo> getUserList(){
        return new ArrayList<UserVo>(){{this.add(new UserVo());}};
    }

    @PostMapping("login")
    @ApiOperation(value = "登陆")
    public ReJson<UserAndTokenVo> login(String account, String password){
        return new ReJson(userService.login(account, password)) ;
    }

    @GetMapping("logout")
    @ApiOperation(value = "退出登录")
    public ReJson logout(){
        return ReJson.OK();
    }
}
